<?php 
    class DormitoryManagementBLL{
        //移除辅导员宿舍管理权限
        public function removeDormitoryManagementJurisdiction($removeList){
            $result=false;
            $dormitoryManagementDAL=new DormitoryManagementDAL();
            $result=$dormitoryManagementDAL->removeDormitoryManagementJurisdiction($removeList);
            if($result){
                $message=array(
                    'code'=>'2001',
                    'message'=>'移除成功'
                );
            }else{
                $message=array(
                    'code'=>'2001',
                    'message'=>'移除失败'
                );
            }
            return $message;
        }
        //获取辅导员列表
        public function getInstructorList($pattern,$grade,$major,$page=0,$pageSize=10,$search){
            $result=null;
            $action=$this->searchPatternSelection($grade,$major,$search);
            $dormitoryManagementDAL=new DormitoryManagementDAL();
            switch($pattern){
                //查询所有
                case 0:
                    $result=$dormitoryManagementDAL->getInstructorAllList($action,$grade,$major,$page*$pageSize,$pageSize,$search);
                    break;
                //查询已分配
                case 1:
                    $result=$dormitoryManagementDAL->getInstructorList($action,$grade,$major,$page*$pageSize,$pageSize,$search);
                    break;
                //查询未分配
                case 2:
                    $result=$dormitoryManagementDAL->getInstructorNoList($action,$grade,$major,$page*$pageSize,$pageSize,$search);
                    break;
                default:
                break;
            }
            
            return $result;
        }
        
        //获取辅导员列表页数
        public function getInstructorListPage($pattern,$grade,$major,$pageSize=20,$search){
            $pageMax=0;
            $count=0;
            $result=null;
            $action=$this->searchPatternSelection($grade,$major,$search);
            $dormitoryManagementDAL=new DormitoryManagementDAL();
            switch($pattern){
                case 0:
                    $result=$dormitoryManagementDAL->getInstructorAllListPage($action,$grade,$major,$search);
                    break;
                case 1:
                    $result=$dormitoryManagementDAL->getInstructorListPage($action,$grade,$major,$search);
                    break;
                case 2:
                    $result=$dormitoryManagementDAL->getInstructorNoListPage($action,$grade,$major,$search);
                    break;
                default:
                break;
            }
            if($result!=null){
                $count=$result['count'];
            }
            if($count>$pageSize){
                if($count%$pageSize===0){
                    $pageMax=(int)($count/$pageSize);
                }else{
                    $pageMax=(int)($count/$pageSize)+1;
                }
            }
            return $pageMax;
        }


        //获取辅导员所管理的宿舍的数量
        public function getInstructorDormitoryNumber($instructorID,$grade,$major){
            $pattern=0;
            $dormitoryManagementDAL=new DormitoryManagementDAL();
            if($grade===0&&$major===0){
                $pattern=1;
            }else if($grade===0){
                $pattern=2;
            }else if($major===0){
                $pattern=3;
            }else{
                $pattern=4;
            }
            $result=$dormitoryManagementDAL->getInstructorDormitoryNumber($pattern,$instructorID,$grade,$major);
            $number=$result['count'];

            return $number;
        }

        //获取查询模式
        public function searchPatternSelection($grade,$major,$search){
            $pattern=0;
            if($grade==0&&$major==0){
                if($search==''){
                    $pattern=1;
                }else{
                    $pattern=2;
                }   
            }else if($grade==0){
                if($search==''){
                    $pattern=3;
                }else{
                    $pattern=4;
                }
            }else if($major==0){
                if($search==''){
                    $pattern=5;
                }else{
                    $pattern=6;
                }
            }else{
                if($search==''){
                    $pattern=7;
                }else{
                    $pattern=8;
                }
            }
            return $pattern;
        }
        
    }
?>